package com.cskaoyan.service.impl;

import com.cskaoyan.bean.bo.WxFeedbackBo;
import com.cskaoyan.bean.bo.WxFeedbackBo1;
import com.cskaoyan.bean.pojo.MallFeedback;
import com.cskaoyan.bean.pojo.MallUser;
import com.cskaoyan.mapper.MallFeedbackMapper;
import com.cskaoyan.service.WxFeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Author: chaohe@com.cskaoyan
 * @Date: 2021/7/12
 * @Time: 10:32
 */
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {

    @Autowired
    MallFeedbackMapper mallFeedbackMapper;
    /**
     * @Author chaohe
     * @description: 微信小程序的提交
     * @Date 17:46 2021/7/12
     * url: http://localhost:8083/wx/feedback/submit
     */


    @Override
    public void submit(WxFeedbackBo wxFeedbackBo) {

        //无法获得关于用户的信息，待指定
        String[] picUrls = wxFeedbackBo.getPicUrls();
        MallFeedback mallFeedback = new MallFeedback();
        for (String picUrl : picUrls) {
            mallFeedback.setMobile(wxFeedbackBo.getMobile());
            mallFeedback.setFeedType(wxFeedbackBo.getFeedType());
            mallFeedback.setContent(wxFeedbackBo.getContent());
            mallFeedback.setHasPicture(wxFeedbackBo.getHasPicture());

            mallFeedback.setPicUrls(picUrl);

            mallFeedback.setStatus(0);



            Subject subject = SecurityUtils.getSubject();
            MallUser mallUser = (MallUser) subject.getPrincipal();
            Integer id = mallUser.getId();
            mallFeedback.setUserId(id);
            String nickname = mallUser.getNickname();
            mallFeedback.setUsername(nickname);

            Date date = new Date();
            Timestamp timestamp = new Timestamp(date.getTime());

            mallFeedback.setAddTime(timestamp);
            mallFeedback.setUpdateTime(timestamp);

            mallFeedbackMapper.insert(mallFeedback);
        }


    }


}
